
 
***************************************************
* Comparison with Trounsinte model 
***************************************************


**********************************
* Create Table B.6- Column 1
**********************************

/* NOTE: The first column is created using the data from Trounstine (2015). It can be found at: 

https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/4LZXTY

It is the data set named final_seg

Column 1 in Table B.6 is created by using that data set and the following line of code:
*/
eststo troun1: xtreg dgepercap_cpi H_citytract_NHW_i pctblkpopinterp pctasianpopinterp pctlatinopopinterp chng5pctblk chng5pctlatino chng5pctasian  medinc_cpi pctlocalgovworker_100 pctrentersinterp pctover65 pctcollegegradinterp logpop if totaltracts>1 &  dgepercap_cpi~=0,fe vce(cluster geo_id2)


* This is the main data plus data from the final_seg data set. It includes additional variables from this data set for city and county based school districts. 
use comparison_data, clear
tsset ncesid year, yearly
sort ncesid year

* check correlation on segregation measures 
corr H_citytract_NHW_i TheileH_wb_ipo TheileH_wnw_ipo



**********************************
* Create Table B.6- Column 2-7
**********************************

* Trounstine Data subset to cities we both have
eststo troun2: xtreg dgepercap_cpi H_citytract_NHW_i pctblkpopinterp pctasianpopinterp pctlatinopopinterp chng5pctblk chng5pctlatino chng5pctasian  medinc_cpi pctlocalgovworker_100 pctrentersinterp pctover65 pctcollegegradinterp logpop if totaltracts>1 &  dgepercap_cpi~=0,fe vce(cluster geo_id2)
* Trounstine Dependent variable 
eststo troun3: xtreg dgepercap_cpi TheileH_wb_ipo  per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year , i(ncesid) fe robust
gen sample_troun=e(sample)
sort ncesid year

gen f1per_pupil_local_thous=f1.per_pupil_local_thous
* My dependent variable and model- 2504590 doesn't have DGE so not including in these
eststo troun4: xtreg f1per_pupil_local_thous TheileH_wb_ipo  per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if ncesid~=2504590 & merge_trounstine==3  & tract_count>1&  black_count>0  , i(ncesid) fe 
* Fewer years
eststo troun5: xtreg f1per_pupil_local_thous TheileH_wb_ipo  per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if ncesid~=2504590 & merge_trounstine==3 & tract_count>1&  black_count>0 & (year==1995 | year==1997 | year==2002 | year==2007 | year==2010), i(ncesid) fe 
* matching Trounstine specifiation 
eststo troun6: xtreg f1per_pupil_local_thous TheileH_wb_ipo  per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if ncesid~=2504590 & merge_trounstine==3  & tract_count>1 &  black_count>0 , i(ncesid) fe vce(cluster ncesid)
* Fewer years
eststo troun7: xtreg f1per_pupil_local_thous TheileH_wb_ipo  per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep if ncesid~=2504590 & merge_trounstine==3 & tract_count>1 &  black_count>0  & (year==1995 | year==1997 | year==2002 | year==2007 | year==2010), i(ncesid) fe vce(cluster ncesid)

* Full Model
eststo troun8: xtreg f1per_pupil_local_thous c.TheileH_wb_ipo c.per_black_ipo per_hispanic_ipo change_black_5years change_hispanic_5years $indep i.year if  (gov_type=="3" | gov_type=="2" | gov_type=="1")  &tract_count>1 &  black_count>0 , fe i(ncesid) vce(cluster ncesid)
 

esttab troun1 troun2 troun3 troun4  troun5  troun6   troun8 using "table_trounstine.tex", label  title(Regression table\label{tab1}) replace nostar cells(b(star fmt(2)) se(par fmt(3)))  width(0.8\hsize) ///
 drop( 1995.year 1996.year 1997.year 1998.year 1999.year 2000.year 2001.year 2002.year 2003.year 2004.year 2005.year 2006.year 2007.year 2008.year 2009.year 2010.year) 

************************
* Create Figure 5 
************************


 coefplot (troun1, rename(H_citytract_NHW_i = rob1)  mlabels(H_citytract_NHW_i = 12 "cities (N=2,637)" )) (troun2, rename(H_citytract_NHW_i = rob2) mlabels(H_citytract_NHW_i = 12 "cities (N=133)")) (troun3, rename(TheileH_wb_ipo = rob3) mlabels(TheileH_wb_ipo = 11 "cities(N=476)")) ///
           (troun4, rename(TheileH_wb_ipo = rob4) mlabels(TheileH_wb_ipo = 12 "cities (N=476)")) (troun5, rename(TheileH_wb_ipo  = rob5) mlabels(TheileH_wb_ipo = 12 "cities (N=476)")) (troun6, rename(TheileH_wb_ipo = rob6) mlabels(TheileH_wb_ipo = 12 "cities(N=476)")) ///
		    (troun7, rename(TheileH_wb_ipo = rob7) mlabels(TheileH_wb_ipo = 12 "cities (N=476)"))   (troun8, rename(TheileH_wb_ipo = rob8) mlabels(TheileH_wb_ipo = 12 "cities/counties (N=824)")), ///
			  grid( glcolor(white)) keep(TheileH_wb_ipo H_citytract_NHW_i) xtitle("Revenue or Expenditures (in thousands)") xline(0)  mcolor(black) ciopts(lcolor(black))  msymbol(D) mfcolor(white) scheme(s1mono) legend(off)  ///
			     graphregion(margin(l=60)) yscale(alt noline) title("95% CI for Segregation Coefficient ", span) ///
	coeflabels(rob1 = "1. Trounstine Model" rob2 = "2. Subset to Matched Citites"  rob3= "3. Change to my indep vars" ///
		  rob4 = "4. Change to School Depend Var" rob5="5. Years 95, 97, 02, 07, 10" rob6="6. Cluster Errors by district" ///
	           rob7 = "7. Cluster Errors & Fewer Years" rob8 = "8. All City/County Districts" /// 
				  , wrap(35) notick labgap(-125)) headings(rob1="Direct General Expenditures" rob4 ="School District Revenue" ,	 labgap(-130) nogap  labsize(medlarge) labcolor(gray)) 
		graph export "graph_trounstine.pdf", as(pdf) replace
